﻿<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    Sub LoginBtn_Click(Sender As Object, E As EventArgs)
    
        If Page.IsValid Then
            dim cnn as new OleDbConnection(ConfigurationSettings.AppSettings("strcnn"))
            cnn.Open()
    
            dim cmd as new OleDbCommand("select count(*) as cont from usuario where login='" & Replace(UserName.Text, "'", "") & "' and senha='" & Replace(UserPass.Text, "'", "") & "'", cnn)
    
            dim dr as OleDbDataReader
    
            dr = cmd.ExecuteReader()
    
            dr.Read()
    
	    If dr("cont") <> 0 Then
                FormsAuthentication.RedirectFromLoginPage(UserName.Text, true)
            Else
                Msg.Text = "Login ou senha inválido!"
            End If
        End If
    
    End Sub

</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
    <form runat="server">
        <table bordercolor="navajowhite" cellspacing="0" cellpadding="2" width="950" align="center" bgcolor="floralwhite">
            <tbody>
                <tr>
                    <td valign="center" align="middle" bgcolor="#ffdead" colspan="2">
                        <h2>Login 
                        </h2>
                    </td>
                </tr>
                <tr>
                    <td valign="top" align="middle">
                        <asp:Label id="Msg" runat="server" forecolor="red"></asp:Label>
                        <br />
                        <br />
                        <table>
                            <tbody>
                                <tr>
                                    <td>
                                        Login:</td>
                                    <td>
                                        <asp:TextBox id="UserName" runat="server"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:RequiredFieldValidator id="RequiredFieldValidator3" runat="server" ControlToValidate="UserName" ErrorMessage="*"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Senha:</td>
                                    <td>
                                        <asp:TextBox id="UserPass" runat="server" TextMode="Password"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:RequiredFieldValidator id="RequiredFieldValidator4" runat="server" ControlToValidate="UserPass" ErrorMessage="*"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                    <td>
                                        <asp:button id="LoginBtn" onclick="LoginBtn_Click" runat="server" text="Login"></asp:button>
                                    </td>
                                    <td>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</body>
</html>
